import { ref, computed } from 'vue';
import { DirSign } from '../common.js';

/**
 * @param {import('vue').Ref<number>} i
 * @param {'prev' | 'next'} dir
 */
export function setIndex(i, dir) {
  i.value = i.value + DirSign(dir);
  return i;
}

export function useSwitchIndex(xs) {
  const i = ref(0);

  const switchable = computed(() => ({
    prev: 0 < i.value,
    next: i.value + 1 < xs.value.length,
  }));

  return { i, switchable };
}
